// [[ OnflowGenerator File UUID: f3d44071b1944c029a60ed40485e82f5  ]]
package com.itdct.onflow.system.log.service

import com.itdct.onflow.core.constant.CommonString
import com.itdct.onflow.core.constant.ReturnCode
import com.itdct.onflow.core.extend.*
import com.itdct.onflow.core.vo.RespPageVo
import com.itdct.onflow.core.vo.RespVo
import com.itdct.onflow.system.common.base.BaseSysService
import com.itdct.onflow.system.common.context.Context
import com.itdct.onflow.system.common.extend.dict
import com.itdct.onflow.system.log.entity.SysImportantApiLogEntity
import com.itdct.onflow.system.log.mapper.SysImportantApiLogMapper
import com.itdct.onflow.system.log.qo.SysImportantApiLogEditQo
import com.itdct.onflow.system.log.qo.SysImportantApiLogSearchQo
import com.itdct.onflow.system.log.vo.SysImportantApiLogDetailVo
import com.itdct.onflow.system.log.vo.SysImportantApiLogListVo
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

/**
 * @author DCTANT
 * @date 2025-09-23 15:03:31
 * @version 1.0
 * @description 系统重要接口访问日志服务
 */
@Service
class SysImportantApiLogService(
    val sysImportantApiLogMapper: SysImportantApiLogMapper
) : BaseSysService() {

    @Transactional(rollbackFor = [Exception::class])
    fun add(qo: SysImportantApiLogEditQo, context: Context): RespVo<Long> {
        val addEntity = qo.toEntity(SysImportantApiLogEntity::class.java)
        val id = sysImportantApiLogMapper.insertEx(addEntity)
        return success(id)
    }

    @Transactional(rollbackFor = [Exception::class])
    fun update(qo: SysImportantApiLogEditQo, context: Context): RespVo<Unit> {
        val updateEntity = sysImportantApiLogMapper.selectByIdEx(qo.id)
        qo.injectValue(updateEntity)
        sysImportantApiLogMapper.updateEx(updateEntity)
        return success()
    }

    fun delete(qo: SysImportantApiLogEditQo, context: Context): RespVo<Unit> {
        val ids = qo.ids ?: fail(ReturnCode.LACK_PARAM, CommonString.REQUIRE_DELETE_ID_LIST)
        val deleteEntities = sysImportantApiLogMapper.selectByIdsEx(ids)
        sysImportantApiLogMapper.deleteBatchEx(deleteEntities)
        return success()
    }

    fun detail(qo: SysImportantApiLogSearchQo, context: Context): RespVo<SysImportantApiLogDetailVo> {
        val id = qo.id ?: fail(ReturnCode.LACK_PARAM, CommonString.REQUIRE_ID)
        val vo = sysImportantApiLogMapper.findById(id) ?: fail(CommonString.ENTITY_NOT_FOUND_USAGE("系统重要接口访问日志", id))
        return success(vo.dict())
    }

    fun page(qo: SysImportantApiLogSearchQo, context: Context): RespPageVo<SysImportantApiLogListVo> {
        startPage(context)
        val pageData = sysImportantApiLogMapper.findByList(qo)
        return successPage(pageData.dict())
    }

// [[ OnflowGenerator Range (- selectFunctions -) Start ]]

// [[ OnflowGenerator Range (- selectFunctions -) End ]]
}